package com.curry.apiprovider.generator.web;

import com.curry.apiprovider.response.ResponseEntity;
import com.curry.apiprovider.response.ResultCode;
import com.curry.apiprovider.response.ResultRow;
import com.curry.apiprovider.util.BindResultUtils;
import org.springframework.validation.BindingResult;

import java.util.List;

public class BaseController {


    public <T> ResponseEntity buildResultList(List<T> data, ResultCode resultCode) {
        ResponseEntity responseEntity = new ResponseEntity();
        responseEntity.setCode(resultCode.getCode());
        responseEntity.setMessage(resultCode.getMessage());
        ResultRow resultRow = new ResultRow(data, data.size());
        responseEntity.setData(resultRow);
        return responseEntity;
    }

    public <T> ResponseEntity buildResultObj(Object data, ResultCode resultCode) {
        ResponseEntity responseEntity = new ResponseEntity();
        responseEntity.setCode(resultCode.getCode());
        responseEntity.setMessage(resultCode.getMessage());
        ResultRow resultRow = new ResultRow(data, 1);
        responseEntity.setData(resultRow);
        return responseEntity;
    }
    public <T> ResponseEntity buildResultNormalObj(Object data, ResultCode resultCode) {
        ResponseEntity responseEntity = new ResponseEntity();
        responseEntity.setCode(resultCode.getCode());
        responseEntity.setMessage(resultCode.getMessage());
        responseEntity.setData(data);
        responseEntity.setCount(data instanceof List?((List) data).size():1);
        return responseEntity;
    }

}
